import java.io.*;
import java.util.Vector;



public class cc {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		Vector<String> classNames = new Vector<String>();
	    
	    try 
	    {
	    	StringBuilder builder = new StringBuilder();
	    	java.net.URL vv = cc.class.getResource("list.txt");
	    	String sf = GetNormalFileName(vv.getFile());
	    	Reader r = new FileReader(sf);
	    	BufferedReader input =  new BufferedReader(r);
	    	try 
	    	{
	    		String line = null; 
	    		while (( line = input.readLine()) != null)
	    		{
	    			String[] vals = line.split("\t");
	    			classNames.add(vals[0]);
	    			builder.append("modes.add(new " + vals[0] + "());");
	    		}
	    	}
	    	finally {
	    		input.close();
	    	}
	    	
	    	String fileTestWindowContent = getContents(GetNormalFileName(cc.class.getResource("testWindow.template").getFile()));
	    	fileTestWindowContent = fileTestWindowContent.replaceFirst("###REPLACE###", builder.toString());
	    	write("testWindow.java", fileTestWindowContent);
	    }
	    catch (IOException ex){
	    	ex.printStackTrace();
	    }
	    
	    
	    
	}
	
	static public String getContents(String fileName) 
	{	    
	    StringBuilder contents = new StringBuilder();
	    
	    try 
	    {
	    	BufferedReader input =  new BufferedReader(new FileReader(fileName));
	    	try 
	    	{
	    		String line = null; 
	    		while (( line = input.readLine()) != null)
	    		{
	    			contents.append(line);
	    			contents.append(System.getProperty("line.separator"));
	    		}
	    	}
	    	finally 
	    	{
	    		input.close();
	    	}
    	}
	    catch (IOException ex){
	    	ex.printStackTrace();
	    }
	    
	    return contents.toString();
	}	
	
	static void write(String fileName, String text) throws IOException 
	 {		 
		 Writer out = new OutputStreamWriter(new FileOutputStream(fileName));
		 try 
		 {
			 out.write(text);
		 }
		 finally 	
		 {
			 out.close();
		 }
	 }

	static String GetNormalFileName(String fname){
		
		String newFname = fname.replaceFirst("/", "");
		newFname = newFname.replaceAll("%20", " ");
		return newFname;
	}
}
